package com.gc.baselib.manager

import android.content.Context
import java.io.File

object FilePathManager {
    private lateinit var mContext: Context
    private var rootPath: String? = null
    fun initContext(context: Context) {
        mContext = context
        var externalFilesDir = context.getExternalFilesDir(null)?:context.filesDir
        rootPath=externalFilesDir.absolutePath+File.separator
        ///storage/emulated/0/Android/data/com.zk.duoting/files
        ///data/user/0/com.zk.duoting/files
    }
    fun setAppRootPath(rootPath:String){
        this.rootPath=rootPath
    }
    private fun getAppRootPath(): String? {
        return rootPath /*+ CoreApi.getInstance().context.packageName + File.separator*/
    }
    fun getCachePath(): String? {
        val filePath: String = getAppRootPath() + "cache" + File.separator
        createFolder(filePath)
        return filePath
    }
    fun getTempPath(): String? {
        return getAppRootPath() + "temp" + File.separator
    }
    private fun createFolder(filePath: String?) {
        val file = File(filePath)
        if (!file.exists()) {
            file.mkdirs()
        }
    }
    fun getLogPath(): String? {
        return getAppRootPath() + "log" + File.separator
    }

    fun getDbPath(): String? {
        return getAppRootPath() + "db" + File.separator
    }
}